import com.lagou.domain.Article;
import com.lagou.domain.Comment;
import com.lagou.mapper.ArticleMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {
    private SqlSession sqlSession;
    private SqlSessionFactory sqlSessionFactory;
    @Before
    public void before()throws IOException{
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        sqlSession=sqlSessionFactory.openSession();
    }

    @Test
    public void testSelectArticle(){
        ArticleMapper mapper = sqlSession.getMapper(ArticleMapper.class);
        Article article = mapper.findArticle(1);
        System.out.println(article);
        System.out.println(article.getCommentList().toString());

    }

    @After
    public void after(){
        sqlSession.commit();
        sqlSession.close();
    }
}
